home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / NET / BR.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  9KB  |  306 lines

  1. /*
  2.  * Constants and structure definitions for the bridging code
  3.  */
  4.  
  5. #if !defined(One)
  6. #define Zero    0
  7. #define One    1
  8. #endif  /* !defined(One) */
  9.  
  10. #if !defined(TRUE)
  11. #define FALSE   0
  12. #define TRUE    1
  13. #endif /* !defined(TRUE) */
  14.  
  15. /** port states. **/
  16. #define Disabled    0              /* (4.4 5)     */
  17. #define Listening    1              /* (4.4.2)     */
  18. #define Learning    2              /* (4.4.3)     */
  19. #define Forwarding    3              /* (4 4 4)     */
  20. #define Blocking    4              /* (4.4.1)     */
  21.  
  22. #define No_of_ports 8
  23. /* arbitrary choice, to allow the code below to compile */
  24.  
  25. #define All_ports (No_of_ports + 1)
  26.  
  27. /*
  28.  * We time out our entries in the FDB after this many seconds.
  29.  */
  30. #define FDB_TIMEOUT    20 /* JRP: 20s as NSC bridge code, was 300 for Linux */
  31.  
  32. /*
  33.  * the following defines are the initial values used when the 
  34.  * bridge is booted.  These may be overridden when this bridge is
  35.  * not the root bridge.  These are the recommended default values 
  36.  * from the 802.1d specification.
  37.  */
  38. #define BRIDGE_MAX_AGE        20
  39. #define BRIDGE_HELLO_TIME    2
  40. #define BRIDGE_FORWARD_DELAY    15
  41. #define HOLD_TIME        1
  42.  
  43. /* broacast/multicast storm limitation. This per source. */
  44. #define MAX_MCAST_PER_PERIOD    4
  45. #define MCAST_HOLD_TIME        10    /* in jiffies unit (10ms increment) */
  46.  
  47. #define Default_path_cost 10
  48.  
  49. /*
  50.  * minimum increment possible to avoid underestimating age, allows for BPDU
  51.  * transmission time
  52.  */
  53. #define Message_age_increment 1
  54.  
  55. #define No_port 0
  56. /*
  57.  * reserved value for Bridge's root port parameter indicating no root port,
  58.  * used when Bridge is the root - also used to indicate the source when
  59.  * a frame is being generated by a higher layer protocol on this host
  60.  */
  61.  
  62. /** Configuration BPDU Parameters (4.5.1) **/
  63.  
  64. typedef struct {
  65.     union {
  66.         struct {
  67.             unsigned short priority;
  68.             unsigned char ula[6];
  69.         } p_u;
  70.         unsigned int id[2];
  71.     } bi;
  72. } bridge_id_t;
  73.  
  74. #define BRIDGE_PRIORITY    bi.p_u.priority
  75. #define BRIDGE_ID_ULA    bi.p_u.ula
  76. #define BRIDGE_ID    bi.id
  77.  
  78. /* JRP: on the network the flags field is between "type" and "root_id"
  79.  * this is unfortunated! To make the code portable to a RISC machine
  80.  * the pdus are now massaged a little bit for processing
  81.  */ 
  82. #define TOPOLOGY_CHANGE        0x01
  83. #define TOPOLOGY_CHANGE_ACK    0x80
  84. #define BRIDGE_BPDU_8021_CONFIG_SIZE            35    /* real size */
  85. #define BRIDGE_BPDU_8021_CONFIG_FLAG_OFFSET     4
  86. #define BRIDGE_BPDU_8021_PROTOCOL_ID 0
  87. #define BRIDGE_BPDU_8021_PROTOCOL_VERSION_ID 0
  88. #define BRIDGE_LLC1_HS 3
  89. #define BRIDGE_LLC1_DSAP 0x42
  90. #define BRIDGE_LLC1_SSAP 0x42
  91. #define BRIDGE_LLC1_CTRL 0x03
  92.  
  93. typedef struct {
  94.     unsigned short    protocol_id;    
  95.     unsigned char    protocol_version_id;
  96.     unsigned char   type;
  97.     bridge_id_t      root_id;          /* (4.5.1.1)     */
  98.     unsigned int     root_path_cost;      /* (4.5.1.2)     */
  99.     bridge_id_t      bridge_id;          /* (4.5.1.3)     */
  100.     unsigned short   port_id;          /* (4.5.1.4)     */
  101.     unsigned short   message_age;          /* (4.5.1.5)     */
  102.     unsigned short   max_age;          /* (4.5.1.6)     */
  103.     unsigned short   hello_time;          /* (4.5.1.7)     */
  104.     unsigned short   forward_delay;          /* (4.5.1.8)     */
  105.     unsigned char   top_change_ack;
  106.     unsigned char   top_change;
  107. } Config_bpdu;
  108.  
  109. #ifdef __LITTLE_ENDIAN
  110. #define config_bpdu_hton(config_bpdu) \
  111.         (config_bpdu)->root_path_cost = htonl((config_bpdu)->root_path_cost); \
  112.         (config_bpdu)->port_id = htons((config_bpdu)->port_id); \
  113.         (config_bpdu)->message_age = htons((config_bpdu)->message_age); \
  114.         (config_bpdu)->max_age = htons((config_bpdu)->max_age); \
  115.         (config_bpdu)->hello_time = htons((config_bpdu)->hello_time); \
  116.         (config_bpdu)->forward_delay = htons((config_bpdu)->forward_delay);
  117. #else
  118. #define config_bpdu_hton(config_bpdu)
  119. #endif
  120. #define config_bpdu_ntoh config_bpdu_hton
  121.  
  122.  
  123. /** Topology Change Notification BPDU Parameters (4.5.2) **/
  124.  
  125. typedef struct {
  126.     unsigned short    protocol_id;    
  127.     unsigned char    protocol_version_id;
  128.     unsigned char   type;
  129. } Tcn_bpdu;
  130.  
  131. #define BPDU_TYPE_CONFIG    0
  132. #define BPDU_TYPE_TOPO_CHANGE    128
  133.  
  134. /** Bridge Parameters (4.5.3) **/
  135. typedef struct {
  136.     bridge_id_t      designated_root;      /* (4.5.3.1)     */
  137.     unsigned int     root_path_cost;      /* (4.5.3.2)     */
  138.     unsigned int      root_port;          /* (4.5.3.3)     */
  139.     unsigned short   max_age;          /* (4.5.3.4)     */
  140.     unsigned short   hello_time;          /* (4.5.3.5)     */
  141.     unsigned short   forward_delay;          /* (4.5.3.6)     */
  142.     bridge_id_t      bridge_id;          /* (4.5.3.7)     */
  143.     unsigned short   bridge_max_age;      /* (4.5.3.8)     */
  144.     unsigned short   bridge_hello_time;      /* (4.5.3.9)     */
  145.     unsigned short   bridge_forward_delay;      /* (4.5.3.10)     */
  146.     unsigned int     top_change_detected;      /* (4.5.3.11) */
  147.     unsigned int     top_change;          /* (4.5.3.12)     */
  148.     unsigned short   topology_change_time;      /* (4.5.3.13)     */
  149.     unsigned short   hold_time;          /* (4.5.3.14)     */
  150. } Bridge_data;
  151.  
  152. /** Port Parameters (4.5.5) **/
  153. typedef struct {
  154.     unsigned short   port_id;          /* (4.5.5.1)     */
  155.     unsigned int     state;              /* (4.5.5.2)     */
  156.     unsigned int     path_cost;          /* (4.5.5.3)     */
  157.     bridge_id_t      designated_root;      /* (4.5.5.4)     */
  158.     unsigned int     designated_cost;      /* (4.5.5.5)     */
  159.     bridge_id_t      designated_bridge;      /* (4.5.5.6)     */
  160.     unsigned short   designated_port;      /* (4.5.5.7)     */
  161.     unsigned int     top_change_ack;      /* (4.5.5.8)     */
  162.     unsigned int     config_pending;      /* (4.5.5.9)     */
  163.     struct device *dev;    
  164.     struct fdb *fdb;    /* head of per port fdb chain */
  165. } Port_data;
  166.  
  167.  
  168.  
  169. /** types to support timers for this pseudo-implementation. **/
  170. typedef struct {
  171.     unsigned int     active;              /* timer in use. */
  172.     unsigned int     value;              /* current value of timer,
  173.                            * counting up. */
  174. } Timer;
  175.  
  176. struct fdb {
  177.     unsigned char ula[6];
  178.     unsigned char pad[2];
  179.     unsigned short port;
  180.     unsigned int timer;
  181.     unsigned short flags;
  182. #define FDB_ENT_VALID    0x01
  183.     unsigned short mcast_count;
  184.     unsigned int   mcast_timer;        /* oldest xxxxxcast */
  185.     
  186. /* AVL tree of all addresses, sorted by address */
  187.     short fdb_avl_height;
  188.     struct fdb *fdb_avl_left;
  189.     struct fdb *fdb_avl_right;
  190. /* linked list of addresses for each port */
  191.     struct fdb *fdb_next;
  192. };
  193.  
  194. /* data returned on BRCMD_DISPLAY_FDB */
  195. struct fdb_info {
  196.     unsigned char ula[6];
  197.     unsigned char port;
  198.         unsigned char flags;
  199.         unsigned int timer;
  200. };
  201. struct fdb_info_hdr {
  202.     int    copied;            /* nb of entries copied to user */
  203.     int    not_copied;        /* when user buffer is too small */
  204.     int    cmd_time;
  205. };    
  206.  
  207. #define IS_BRIDGED    0x2e
  208.  
  209.  
  210. #define BR_MAX_PROTOCOLS 32
  211. #define BR_MAX_PROT_STATS BR_MAX_PROTOCOLS
  212.  
  213. /* policy values for policy field */
  214. #define BR_ACCEPT 1
  215. #define BR_REJECT 0
  216.  
  217. /* JRP: extra statistics for debug */
  218. typedef struct {
  219.     /* br_receive_frame counters */
  220.     int port_disable_up_stack;
  221.     int rcv_bpdu;
  222.     int notForwarding;
  223.     int forwarding_up_stack;
  224.     int unknown_state;
  225.  
  226.     /* br_tx_frame counters */
  227.     int port_disable;
  228.     int port_not_disable;
  229.  
  230.     /* br_forward counters */
  231.     int local_multicast;
  232.     int forwarded_multicast;    /* up stack as well */
  233.     int flood_unicast;
  234.     int aged_flood_unicast;
  235.     int forwarded_unicast;
  236.     int forwarded_unicast_up_stack;
  237.     int forwarded_ip_up_stack;
  238.     int forwarded_ip_up_stack_lie;    /* received on alternate device */
  239.     int arp_for_local_mac;
  240.     int drop_same_port;
  241.     int drop_same_port_aged;
  242.     int drop_multicast;
  243. } br_stats_counter;
  244.  
  245. struct br_stat {
  246.     unsigned int flags;
  247.     Bridge_data bridge_data;
  248.     Port_data port_data[No_of_ports];
  249.     unsigned int policy;
  250.     unsigned int exempt_protocols;
  251.     unsigned short protocols[BR_MAX_PROTOCOLS];
  252.     unsigned short prot_id[BR_MAX_PROT_STATS];    /* Protocol encountered */
  253.     unsigned int prot_counter[BR_MAX_PROT_STATS];    /* How many packets ? */
  254.     br_stats_counter packet_cnts;
  255. };
  256.  
  257. /* defined flags for br_stat.flags */
  258. #define BR_UP        0x0001    /* bridging enabled */
  259. #define BR_DEBUG    0x0002    /* debugging enabled */
  260. #define BR_PROT_STATS    0x0004    /* protocol statistics enabled */
  261. #define BR_STP_DISABLED    0x0008    /* Spanning tree protocol disabled */
  262.  
  263. struct br_cf {
  264.     unsigned int cmd;
  265.     unsigned int arg1;
  266.     unsigned int arg2;
  267. };
  268.  
  269. /* defined cmds */
  270. #define    BRCMD_BRIDGE_ENABLE    1
  271. #define    BRCMD_BRIDGE_DISABLE    2
  272. #define    BRCMD_PORT_ENABLE    3    /* arg1 = port */
  273. #define    BRCMD_PORT_DISABLE    4    /* arg1 = port */
  274. #define    BRCMD_SET_BRIDGE_PRIORITY    5    /* arg1 = priority */
  275. #define    BRCMD_SET_PORT_PRIORITY    6    /* arg1 = port, arg2 = priority */
  276. #define    BRCMD_SET_PATH_COST    7    /* arg1 = port, arg2 = cost */
  277. #define    BRCMD_DISPLAY_FDB    8    /* arg1 = port */
  278. #define    BRCMD_ENABLE_DEBUG    9
  279. #define    BRCMD_DISABLE_DEBUG    10
  280. #define BRCMD_SET_POLICY    11    /* arg1 = default policy (1==bridge all) */
  281. #define BRCMD_EXEMPT_PROTOCOL    12    /* arg1 = protocol (see net/if_ether.h) */
  282. #define BRCMD_ENABLE_PROT_STATS    13
  283. #define BRCMD_DISABLE_PROT_STATS 14
  284. #define BRCMD_ZERO_PROT_STATS    15
  285. #define BRCMD_TOGGLE_STP    16
  286.  
  287. /* prototypes of exported bridging functions... */
  288.  
  289. void br_init(void);
  290. int br_receive_frame(struct sk_buff *skb);    /* 3.5 */
  291. int br_tx_frame(struct sk_buff *skb);
  292. int br_ioctl(unsigned int cmd, void *arg);
  293. int br_protocol_ok(unsigned short protocol);
  294. void requeue_fdb(struct fdb *node, int new_port);
  295.  
  296. struct fdb *br_avl_find_addr(unsigned char addr[6]);
  297. struct fdb *br_avl_insert (struct fdb * new_node);
  298. void sprintf_avl (char **pbuffer, struct fdb * tree, off_t *pos,int* len, off_t offset, int length);
  299. int br_tree_get_info(char *buffer, char **start, off_t offset, int length, int dummy);
  300. void br_avl_delete_by_port(int port);
  301. /* externs */
  302.  
  303. extern struct br_stat br_stats;
  304. extern Port_data port_info[];
  305.  
  306.